#!/bin/sh

case "$1" in
        start)
                echo "Starting wifihot:"
                echo 1 >  /proc/sys/net/ipv4/ip_forward
                export XTABLES_LIBDIR=/lib/xtables
                iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
                iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT
                iptables -A FORWARD -d 192.168.0.0/24 -j ACCEPT
                sysctl -p

                ifconfig eth0 192.168.3.110
                ifconfig wlan0 up 192.168.0.1	

                touch /etc/udhcpd.leases
                udhcpd /etc/wifihot/udhcpd.conf -f wlan0 &
                
                hostapd /etc/wifihot/hostapd.conf -dd -B
                hostapd_cli -p /var/run/hostapd -i wlan0 -a event_handler.sh
                ;;
        stop)
                printf "Stopping wifihot: "
                
                ;;
        restart|reload)
                $0 stop
                $0 start
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                exit 1
esac

exit 0
